#!/bin/bash

# 自动安装docker rabbitmq脚本
# 运行:
# sudo curl -L http://file.sxycy.cn:88/vod/download/rabbitmq/install.sh -o /tmp/docker-rabbitmq-install.sh && sudo chmod +x /tmp/docker-rabbitmq-install.sh && sudo /tmp/docker-rabbitmq-install.sh && sudo rm -f /tmp/docker-rabbitmq-install.sh

#检查curl是否已安装
is_exist(){
  x=`rpm -qa | grep $1 |wc -l `
  if [ x > 0  ];then
    echo -e "yes,the $1 has installed,$x"
    return 1
  else
    echo "not install $1,$x"
    return 0
  fi
}

is_exist 'curl'
if [ $? == 0 ]; then
  sudo yum -y install curl
fi

dirpath="/tmp/docker_install_"$RANDOM

if [ ! -d $dirpath ]; then
 sudo mkdir $dirpath
fi

cd $dirpath

#curl -L "http://file.sxycy.cn:88/vod/download/rabbitmq/plugins.erl" -o $dirpath"/plugins.erl"
sudo curl -L "http://file.sxycy.cn:88/vod/download/rabbitmq/Dockerfile" -o $dirpath"/Dockerfile"

cd $dirpath

sudo docker build -t weiguoxin/rabbitmq .

sudo docker run -d --name rabbitmq -p 15672:15672 -p61613:61613 weiguoxin/rabbitmq

sudo rm -drf $dirpath

